import router from "@/router";
import store from "@/store"
import {getToken} from "@/utils/cache"
import setting from "./setting";
// 白名单
export const whitelist = ['/ec'];
router.beforeEach(async (to,form,next) => {
  if(to.meta && to.meta.title){
    document.title = to.meta.title
  }else{
    document.title = setting.appTitle;
  }
  let hashToken = getToken();
  // 首先排除掉白名单中的页面
  if(whitelist.includes(to.path)){
      next()
    return
  }
  // 如果有token
  if(hashToken){
    if(to.path === '/login'){
      next('/home');
      return
    }else{
      next()
      return
    }
  }else{
    
    // 一开始进来,没有token
    // 没有token的情况下,且即将去的页面不是login
    if(to.path !== '/login'){
      next('/login');
    }else{
      next()
    }
  }
})